package com.resource.manager.search.vo;

import cn.hutool.core.util.ObjectUtil;
import lombok.Data;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

@Data
public class MainSearchEntity implements Serializable {

    /**
     * 是否已查询
     */
    private boolean searchFlag;

    /**
     *
     */
    private String path;

    /**
     * 文件类型划分
     */
    private List<FileTypeEntity> fileTypeEntitys = new ArrayList<>();

    private List<FileTypeEntity> allFileTypeEntitys = new ArrayList<>();

    public void calSLocal(int width){

        int startX = 10;
        int startY = 10;
        for (FileTypeEntity type : fileTypeEntitys) {
            type.setSX(startX);
            type.setSY(startY);
            type.setSWidth(width);

            startY += type.getSHeight() + 10;
        }
        initCheckFlag();
    }

    public void initCheckFlag(){
        boolean existCheck = fileTypeEntitys.stream().anyMatch(f -> Boolean.TRUE.equals(f.isSCheckFlag()));
        if(!existCheck && !ObjectUtil.isEmpty(fileTypeEntitys)){
            fileTypeEntitys.get(0).setSCheckFlag(true);
        }
    }

    public void setSCheckFlagTrue(FileTypeEntity entity){
        fileTypeEntitys.forEach(f -> f.setSCheckFlag(false));
        entity.setSCheckFlag(true);
    }

}
